package com.projectbox.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.projectbox.dao.AnnouncementDao;
import com.projectbox.service.UserService;

@Controller
@RequestMapping("/announcement")
public class AnnouncementController {

	private Logger logger = LoggerFactory.getLogger(getClass()); 
	
	private AnnouncementDao announcementDao;
	private UserService userService;
	
	public void setAnnouncementDao(AnnouncementDao announcementDao) {
		this.announcementDao = announcementDao;
	}
	
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	@RequestMapping(method = RequestMethod.GET)
    public String displayAnnounments(Model model) {
		model.addAttribute("announcements",
				this.announcementDao.getAnnouncements());
		
		logger.debug(userService.getCurrentUser().toString());
		
		model.addAttribute("user", userService.getCurrentUser());
		
		return "announcement";
	}
}
